#include "head.h"

int enqueue(queue_t* q, int net_fd){

    node_t* node = (node_t*)malloc(sizeof(node_t));
    if(!node){
        fprintf(stderr, "%s : %s : %d\n", __FILE__, __FUNCTION__, __LINE__);
        return -1;
    }

    node->net_fd = net_fd;
    node->next = NULL;

    if(!q->head){

        q->head = node;
        q->end = node;
    }else{

        q->end->next = node;
        q->end = node;
    }

    q->size++;


    return 0;
}

int dequeue(queue_t* q){

    if(q->size == 0){
        fprintf(stderr, "Queue is null\n");
        return -1;
    }

    node_t* node = q->head;

    q->head = q->head->next;
    
    if(q->size == 1){
        q->end = NULL;
    }

    q->size--;

    free(node);


    return 0;
}
